package com.lr.chat;

import java.io.DataInputStream;
import java.io.IOException;
import java.net.Socket;

public class Recieve implements Runnable{

	private DataInputStream dis;
	
	private boolean isRunning = true;
	
	public Recieve(Socket socket){
		try {
			dis = new DataInputStream(socket.getInputStream());
		} catch (IOException e) {
			stop();
			IOUtil.IOClose(dis);
		}
	}
	
	public void recieveMsg(){
		try {
			String msg = dis.readUTF();
			System.out.println(msg);
		} catch (IOException e) {
			stop();
			IOUtil.IOClose(dis);
		}
	}
	
	@Override
	public void run() {
        while(isRunning){
        	recieveMsg();
        }
	}

	public void stop(){
		isRunning = false;
	}
}
